# install.packages("rmeta")
# install.packages("ggplot2")
# install.packages("dplyr")

library(rmeta)
library(ggplot2)
library(dplyr)

#load coefficients
mechanism <- 
  read.table("data/mechanism.txt")

#compute CIs
mechanism <- 
  mechanism %>% 
  mutate(upper = coef + qnorm(0.975) * se,
         lower = coef + qnorm(0.025) * se)

#create plot
plot <- 
  ggplot(data = mechanism, 
         aes(x = coef, 
             y = plac,
             xmin = lower,
             xmax = upper)) + 
  geom_point() +
  facet_grid(year ~ parent) + 
  geom_errorbarh(height = 0) + 
  scale_y_continuous("", breaks = unique(mechanism$plac),
                     labels = mechanism$labe[1:9]) + 
  theme_classic() + 
  scale_x_continuous("Twinning vs non-twinning") + 
  geom_vline(xintercept = 0, alpha = 0.5, linetype = 2) +  theme(axis.text = element_text(size = 14),
        axis.title = element_text(size = 16),
        strip.text.x = element_text(size = 12),
        strip.text.y = element_text(size = 12),
        title = element_text(size = 16),
        panel.spacing = unit(1, "lines")) 